<template>
  <el-card shadow="never">
    <div slot="header">项目申报审核(科室)</div>
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    >
      <el-table-column slot="submitTime" label="提交日期" width="150" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.submitTime ? formatTime(scope.row.submitTime) : null }}</template>
      </el-table-column>
      <el-table-column slot="action" fixed="right" width="50" align="center">
        <template slot-scope="scope">
          <el-dropdown>
            <a class="el-dropdown-link">
              <i class="el-icon-menu"></i>
            </a>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDetail(scope.row)">
                <a>详情</a>
              </el-dropdown-item>
              <!-- <el-dropdown-item @click.native="handleDelete(scope.row)">
                <a class="red">删除</a>
              </el-dropdown-item>-->
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </e-table>
    <preview-modal ref="previewModal" />
  </el-card>
</template>

<script>
import { planVerifyPage } from '@/api/eval'
import { openNotification } from '@/utils/util'
import PreviewModal from '@/components/PreviewModal'

export default {
  components: {
    PreviewModal
  },
  data() {
    return {
      selectedRows: [],
      tableData: [],
      columns: [
        {
          label: '人物名',
          prop: 'taskTitle'
        },
        {
          label: '提交人',
          prop: 'executorUser'
        },
        {
          label: '科室',
          prop: 'deptName'
        },
        { slot: 'submitTime' },
        // {
        //   slot: 'savePath'
        // },
        {
          slot: 'action'
        }
      ],
      loading: false,
      queryParam: {
        pageSize: 10,
        pageNo: 1
      },
      total: 1
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    handlePreview(record) {
      this.$refs.previewModal.show(record.savePath)
    },
    handleDetail(row) {
      this.$router.push({
        path: '/evaluate/evaluate-planVerifyTable',
        query: { row: JSON.stringify(row) }
      })
    },
    handleDelete(row) {
      const _this = this
      this.$confirm({
        title: '删除操作',
        content: `您确定删除这条申报记录吗？`,
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        centered: true,
        async onOk() {
          // 调用删除接口，刷新表格数据
          const res = await applyDelete(row.evalApplyDetailId, {})
          openNotification('success', '删除成功')
          _this.handleGetList()
        }
      })
    },
    async handleGetList(param = {}) {
      this.loading = true
      const res = await planVerifyPage({ ...this.queryParam, ...param })
      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
